import java.util.*;

public class Main {
    public static int find(int value,int[] table){
        int left=0;
        int right=table.length-1;
        while (left<=right){
            int mid=(left+right)/2;
            if(table[mid]>=value){
                right=mid-1;
            }else{
                left=mid+1;
            }
        }
        return left;
    }
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            int n=scanner.nextInt();
            int m=scanner.nextInt();
            int[] table=new int[n];
            for(int i=0;i<n;i++){
                table[i]=scanner.nextInt();
            }
            int[][] user=new int[m][2];
            for(int i=0;i<m;i++){
                user[i][0]=scanner.nextInt();
                user[i][1]=scanner.nextInt();
            }
            Arrays.sort(table);
            Arrays.sort(user, new Comparator<int[]>() {
                @Override
                public int compare(int[] o1, int[] o2) {
                    return o2[1]-o1[1];
                }
            });
            boolean[] flag=new boolean[n];
            long ret=0;
            int index=0;
            for(int i=0;i<m;i++){
                if(user[i][0]>table[n-1]){
                    continue;
                }
                index=find(user[i][0],table);
                while (index<n&&flag[index]){
                    index++;
                }
                if(index<n){
                    ret+=user[i][1];
                    flag[index]=true;
                }
            }
            System.out.println(ret);
        }
    }



















    public ArrayList<Integer> GetLeastNumbers_Solution(int [] input, int k) {
        ArrayList<Integer> list=new ArrayList<>();
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        for(int i=0;i<input.length;i++){
            if(priorityQueue.size()<k){
                priorityQueue.add(input[i]);
            }else{
                if(!priorityQueue.isEmpty()&&priorityQueue.peek()>input[i]){
                    priorityQueue.poll();
                    priorityQueue.add(input[i]);
                }
            }
        }
        for(int value:priorityQueue){
            list.add(value);
        }
        return list;
    }

















    public static void main1(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            String str=scanner.nextLine();
            int len=str.length();
            int index=0;
            int max=0;
            int start=0;
            int end=0;
            for(int i=0;i<len;i++){
                char ch=str.charAt(i);
                if(ch>='0'&&ch<='9'){
                    index++;
                }else{
                    if(index>max){
                        start=i-index;
                        end=i;
                        max=index;
                    }
                    index=0;
                }
                if(i==len-1&&index!=0&&index>max){
                    start=i-index+1;
                    end=i+1;
                    max=index;
                }
            }
            System.out.println(str.substring(start,end));
        }
    }
}
